package demo1;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-17
 */

interface IUsb {
    void openDevice();
    void closeDevice();
}

class Mouse implements IUsb {
    @Override
    public void openDevice() {
        System.out.println("打开鼠标");
    }

    @Override
    public void closeDevice() {
        System.out.println("关闭鼠标");
    }

    public void click() {
        System.out.println("鼠标点击");
    }
}

class KeyBoard implements IUsb {
    @Override
    public void openDevice() {
        System.out.println("打开键盘");
    }
    @Override
    public void closeDevice() {
        System.out.println("关闭键盘");
    }
    public void input() {
        System.out.println("键盘输入");
    }
}

class Computer {
    public void powerOn() {
        System.out.println("打开电脑");
    }

    public void powerOff() {
        System.out.println("关闭电脑");
    }

    public void useDevice(IUsb use) {
        use.openDevice();

        if (use instanceof Mouse) {
            Mouse tmp = (Mouse)use;
            tmp.click();
        } else if (use instanceof KeyBoard) {
            KeyBoard tmp = (KeyBoard)use;
            tmp.input();
        } else {
            System.out.println("无此设备");
        }

        use.closeDevice();
    }
}